/*******************************************************************************
*   Copyright (C) Harbin Institute of Technology, Shenzhen.
*				  All Rights Reserved.
*   Department: Decoration
********************************************************************************
* File Name   : control_if.h
* Author      : Dayuan
* Version     : v0.01
* Date        : 2019/9/6
* Description : Decoration Rototics Manipulator task.
*******************************************************************************/
/*-History----------------------------------------------------------------------
* Version   Date      Name        Changes and comments
* v0.01     2019/9/6  Dayuan    initial version
*=============================================================================*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _CONTROL_IF_H_
#define _CONTROL_IF_H_

#ifdef __cplusplus
 extern "C" {
#endif
     
/**** Includes ****/
#include "algorithm_if.h"
#include "sensor_if.h"
#include "encoder_if.h"
#include "gpio.h"
     
/**** Definition of constants ****/
#define DX22S
#define CURRENT_CONTROL
/**********PWM frequency to output speed*****************
PWM range 10% ~ 90% to -12400 rpm ~ 12400 rpm

***********PWM frequency to output speed*****************/
#ifdef DX22S
	#ifndef CURRENT_CONTROL
	#define DCX22S_SPEED_MAX 10000
	#else
	#define DCX22S_CURREN_MAX 0.869f
	#define DCX22S_CURRENT2FORCE 0.0153f
	#endif
#endif

 
/**** Definition of types ****/ 


/**** Definition of macros ****/
#define MOTOR_ENABLE() 		HAL_GPIO_WritePin(MOTOR_EN_GPIO_Port,MOTOR_EN_Pin,GPIO_PIN_SET)
#define MOTOR_DISABLE() 	HAL_GPIO_WritePin(MOTOR_EN_GPIO_Port,MOTOR_EN_Pin,GPIO_PIN_RESET)

//#define SPEED_CONTROL
/**** Declaration of constants ****/


/**** Declaration of variables ****/


/**** Declaration of functions ****/
extern void parse_enc_data(SBT_FORCE* sbt, ENC_INC_INFO* encoder, JOINT_INFO* joint);
#ifdef CURRENT_CONTROL
extern int motor_control(float force);
#else
extern int motor_control(float speed);
#endif
extern void motor_encoder_calibration(float speed, JOINT_INFO* joint);
extern float task_cycle(float current_time, uint8_t clear);
extern void motor_enable(void);
extern void motor_disable(void);
extern unsigned char error_detect(SBT_FORCE *sbt, ENC_INC_INFO *encoder, JOINT_INFO *joint);
#ifdef __cplusplus
}
#endif

#endif
